{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# KNN\n",
    "一般来说，KNN解决的是分类问题， 整个计算过程如下\n",
    "1. 计算待分类的物体和其他物体之间的距离\n",
    "2. 统计距离最近的K个邻居\n",
    "3. 对于K个最近的邻居，它们属于的哪个分类最多，待分类物体就属于哪一类\n",
    "\n",
    "在工程学上，我们一般采用交叉验证的方式选取K值\n",
    "\n",
    "## 距离计算方式\n",
    "> 在KNN算法中， 有个重要的变量就是距离。两个样本点之间的距离代表了这两个样本之间的相似度。距离越大，差异性越大；距离越小，相似度越大\n",
    "\n",
    "关于距离的计算方式有下面五种方式：\n",
    "1. 欧氏距离\n",
    "    $$ d = \\sqrt{\\sum_{i=1}^{n}{(x_i-y_i)^2}}$$\n",
    "2. 曼哈顿距离\n",
    "    $$d = |x_1-x_2| + |y_1 - y_2|$$\n",
    "3. 闵可夫斯基距离\n",
    "    $$ d = p \\sqrt{\\sum_{i=1}^{n}{\\mid x_i - y_i \\mid ^p}}$$\n",
    "4. 切比雪夫距离\n",
    "5. 余弦距离"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## KD树\n",
    "\n",
    "一个二叉树的数据结构，方便存储 K 维空间的数据就可以了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
